﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.IO;

namespace WcfCGServicesHost
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        #region Constants

        private const string PackageFolderPrefix = "tmp.";

        #endregion
        
        #region Properties (Private)

        private string TempFolder
        {
            get
            {
                return ConfigurationManager.AppSettings["TempFolder"];
            }
        }

        #endregion

        #region Overrides

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            this.Cleanup();
        }

        #endregion

        #region Methods (Private)

        private void Cleanup()
        {
            string pattern = App.PackageFolderPrefix + "*";
            foreach (string directory in Directory.EnumerateDirectories(this.TempFolder, pattern))
            {
                try
                {
                    Directory.Delete(directory, true);
                }
                catch { };
            }
        }

        #endregion
    }
}
